package com.zcl.controller;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zcl.dao.Sea;
import com.zcl.service.SeaService;

@Controller
public class SeaController {
	@Autowired
	SeaService seaService;
	
	/**
	 * 指向海域页面
	 * @return
	 */
	@RequestMapping("/sea")
	public String seaIndex() {
		return "sea";
	}
	
	/**
	 * 事故信息概况查询
	 */
	@ResponseBody
	@RequestMapping("/sea/surveryQuery")
	public List<Map<String, String>> accidentQuery(Model model) {
		List<Map<String, String>> seaList = seaService.seaQuery();
		return seaList;
	}
	
	/**
	 * 事故信息概况-操作-详情
	 * @return
	 */
	@RequestMapping("/seaSurveryInfo")
	public String accidentSuveryInfo(@RequestParam("seaId") String seaId,Model model) {
		Map<String, String> map = new HashMap<String,String>();
		map.put("seaId", seaId);
		Sea sea = seaService.seaSuveryInfo(map);
		model.addAttribute("sea", sea);
		System.out.println("事故信息概况-操作-详情:accidentId="+seaId);
		return "sea_information";
	}
	
	/**
	 * 事故信息概况-操作-编辑
	 * @return
	 */
	@RequestMapping("/seaSurveryRevise")
	public String seaSuveryRevise(@RequestParam("seaId") String seaId,Model model) {
		Map<String, String> map = new HashMap<String,String>();
		map.put("seaId",seaId);
		Sea sea = seaService.seaSuveryInfo(map);
		model.addAttribute("sea", sea);
		System.out.println("事故信息概况-操作-编辑:seaId="+seaId);
		return "sea_revise";
	}
	
//	/**
//	 * 事故信息概况-操作-编辑2--获取某些下拉框值
//	 * @return
//	 */
//	@ResponseBody
//	@RequestMapping("/seaSurveryRevise2")
//	public Sea accidentSuveryRevise2(@RequestParam("accidentId") String accidentId,Model model) {
//		Map<String, String> map = new HashMap<String,String>();
//		map.put("accidentId", accidentId);
//		Sea sea = seaService.seaSuveryInfo(map);
//		
////		model.addAttribute("accident", accident);
//		System.out.println("事故信息概况-操作-编辑2--获取某些下拉框值:accidentId="+accidentId);
//		return sea;
//	}
	
	/**
	 * 事故信息概况-操作-删除
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/sea/delete")
	public void accidentDelete(@RequestParam("seaId") String seaId) {
		Map<String, String> map = new HashMap<String,String>();
		map.put("seaId", seaId);
		seaService.seaDelete(map);
		System.out.println("删除");;
	}
	
	/**
	 * 事故添加页面
	 * @return
	 */
	@RequestMapping("/seaAdd")
	public String accidentAccidentAdd() {
		return "sea_add";
	}
	
	/**
	 * 事故信息查询-全文搜索
	 * @param search_input
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/sea/globalQuery")
	public List<Map<String, String>> accidentGlobalQuery(@RequestParam("search_input") String search_input){
		Map<String, String> map = new HashMap<String,String>();
		map.put("search_input", search_input);
		List<Map<String, String>> seaList = seaService.seaGlobalQuery(map);
		return seaList;
		
	} 
	
	/**
	 * 事故信息查询-高级搜索
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/sea/advancedQuery")
	public List<Map<String, String>> accidentAdvancedQuery(HttpServletRequest request){
		Map<String, String> map = new HashMap<String,String>();
		
		map.put("seaId", request.getParameter("seaId"));
		map.put("seaName", request.getParameter("seaName"));
		map.put("seaWriter", request.getParameter("seaWriter"));
		map.put("scale", request.getParameter("scale"));
		List<Map<String, String>> seaList = seaService.seaAdvancedQuery(map);
		return seaList;
		
	} 
	
	/**
	 * 事故信息录入
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping("/sea/addSea")
	public void accidentAdd(HttpServletRequest request) throws UnsupportedEncodingException {
		String seaId = UUID.randomUUID().toString();
		Map<String, String> map = new HashMap<String,String>();
		map.put("seaId", seaId);
		map.put("seaName", request.getParameter("seaName"));
		map.put("accidentId", request.getParameter("accidentId"));
		map.put("accidentName", request.getParameter("accidentName"));
		map.put("lng", request.getParameter("lng"));
		map.put("lat", request.getParameter("lat"));
		map.put("scale", request.getParameter("scale"));
		map.put("disadvantage", request.getParameter("disadvantage"));
		System.out.println("seaAdd");
		seaService.seaAdd(map);
	}
	
	/**
	 * 事故信息修改
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping("/sea/reviseSea")
	public void accidentRevise(HttpServletRequest request) throws UnsupportedEncodingException {
		Map<String, String> map = new HashMap<String,String>();
		map.put("seaId", request.getParameter("seaId"));
		map.put("seaName", request.getParameter("seaName"));
		map.put("accidentId", request.getParameter("accidentId"));
		map.put("accidentName", request.getParameter("accidentName"));
		map.put("lng", request.getParameter("lng"));
		map.put("lat", request.getParameter("lat"));
		map.put("scale", request.getParameter("scale"));
		map.put("disadvantage", request.getParameter("disadvantage"));
		System.out.println("seaRevise");
		seaService.seaRevise(map);
	}
}
